package com.neusoft.shopingapi.service;

import com.neusoft.shopingapi.dao.CartDAOImpl;
import com.neusoft.shopingapi.entity.CartEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CartService {
    @Autowired
    private CartDAOImpl dao;
    /**
     *查询购物车商品
     */
    public List<CartEntity> queryCart(Integer userno){
        return dao.queryCart(userno);
    }
    /**
     *添加购物车商品
     */
    public Integer addCart(CartEntity cartEntity){
           List<CartEntity> cartEntityList=dao.queryGoods(cartEntity.getUserno(),cartEntity.getGoodsno());
           if(cartEntityList.size()==1){
               CartEntity cartEntity1 =cartEntityList.get(0);
               cartEntity1.setGoodsquantity(cartEntity1.getGoodsquantity()+1);
               return dao.updateCart(cartEntity1);
           }
        return dao.addCart(cartEntity);
    }
    /**
     *修改购物车商品数量
     */
    public Integer updateCart(CartEntity cartEntity){
        return dao.updateCart(cartEntity);
    }
    /**
     *删除购物车商品
     */
    public Integer delCart(Integer cartno){
        return dao.delCart(cartno);
    }
}
